var app = getApp()
var maxPageIndex
Page({
  /**
   * 页面的初始数据
   */
  data: {
    ifShownoData: true,
    queryInfo: '',
    pageIndex: 1,
    result: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {},
  onShow: function() {
    var that = this
    wx.pageScrollTo({ scrollTop: 0, duration: 0 })
    that.setData({ pageIndex: 1 })
    that.onGetOutSite()
  },

  //到厂数据登记
  goFactoryDataChecked: function(e) {
    let data = e.currentTarget.dataset.data
    wx.navigateTo({
      url: 'factoryData_checked?data=' + JSON.stringify(data)
    })
  },

  //出库登记列表信息
  onGetOutSite: function() {
    var that = this
    var arr = new Array()
    wx.showLoading({
      title: '拼命加载中',
      mask: true
    })

    wx.request({
      method: 'POST',
      url: app.preUrl + 'getOutSite',
      dataType: 'json',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        queryInfo: that.data.queryInfo, //查询信息(输入姓名或者手机号码)
        userId: app.globalData.userId,
        dataType: 2,
        page: that.data.pageIndex, //这里初始值为1
        size: 8
      },
      success: function(res) {
        wx.hideLoading()
        if (res.data.code == 100) {
          maxPageIndex = res.data.total / 8
          arr = res.data.result
          console.log(arr)
          if (that.data.pageIndex != 1) {
            var array = that.data.result
            array = array.concat(arr)
            that.setData({ result: array })
          } else {
            that.setData({ result: arr })
          }
          that.setData({ ifShownoData: true })
        } else if (res.data.code == 400) {
          that.setData({ ifShownoData: false, result: '' })
        } else {
          wx.showModal({
            title: '提示',
            content: res.data.message,
            confirmColor: '#56BDE0',
            showCancel: false
          })
        }
      },
      fail: function(error) {}
    })
  },
  onPullDownRefresh: function() {
    var that = this
    that.setData({
      pageIndex: 1, // 每次触发下拉事件pageIndex=1
      result: ''
    })
    that.onGetOutSite()
    wx.stopPullDownRefresh()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    var that = this
    if (maxPageIndex <= that.data.pageIndex) {
      return
    }
    that.setData({
      pageIndex: that.data.pageIndex + 1
    })

    // 上拉获取更多数据
    that.onGetOutSite()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {}
})
